<template>
  <div :class="classObj" class="subsystem">
    <menus class="sidebar-container" />
    <div :class="{hasTagsView:needTagsView}" class="main-container">
      <div :class="{'fixed-header':fixedHeader}">
        <navbar />
        <tags-view v-if="needTagsView" />
      </div>
      <app-main />
    </div>
  </div>
</template>

<script>
  import router from '../../router/index.js'
  import Menus from './components/Menus'
  import AppMain from './components/AppMain.vue'
  import Navbar from './components/Navbar.vue'
  import TagsView from './components/TagsView/index.vue'
  import {
    mapState
  } from 'vuex'
  export default {
    components: {
      Menus,
      AppMain,
      Navbar,
      TagsView
    },
    data() {
      return {}
    },
    computed: {
      ...mapState({
        sidebar: state => state.app.sidebar,
        device: state => state.app.device,
        needTagsView: state => state.settings.tagsView,
        fixedHeader: state => state.settings.fixedHeader
      }),
      classObj() {
        return {
          hideSidebar: !this.sidebar.opened,
          openSidebar: this.sidebar.opened,
          withoutAnimation: this.sidebar.withoutAnimation,
          mobile: this.device === 'mobile'
        }
      }
    },
    beforeMount() {
      this.loadPage()
    },
    mounted() {
    },
    methods: {
      loadPage: async function() {
        if (this.$store.getters.projectId) {
          this.getMenus()
        } else {
          this.toIndex()
        }
      },
      getMenus: async function() {
        const subsystemRouter = await this.$store.dispatch('subsystem/subsystemMenus', {
          userId: this.$store.getters.id
        })
        router.addRoutes(subsystemRouter)
      },
      toIndex: function(id) {
        this.$router.push('/')
        this.$store.dispatch('tagsView/delSubVisitedViews')
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import "~@/styles/mixin.scss";
  @import "~@/styles/variables.scss";

  .subsystem {
    @include clearfix;
    position: relative;
    height: 100%;
    width: 100%;

    &.mobile.openSidebar {
      position: fixed;
      top: 0;
    }
  }

  .drawer-bg {
    background: #000;
    opacity: 0.3;
    width: 100%;
    top: 0;
    height: 100%;
    position: absolute;
    z-index: 999;
  }

  .fixed-header {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 9;
    width: calc(100% - #{$sideBarWidth});
    transition: width 0.28s;
  }

  .hideSidebar .fixed-header {
    width: calc(100% - 54px)
  }

  .mobile .fixed-header {
    width: 100%;
  }

  .scene {
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 1);
    position: absolute;
    top: 0;
    left: 0;
    z-index: 3000;
    overflow: hidden;

    .frame {
      width: 100%;
      height: 100%;
      overflow: hidden;
    }

    .close-block {
      width: 48px;
      height: 48px;
      background-color: cadetblue;
      border-bottom-left-radius: 100%;
      position: absolute;
      top: 0;
      right: 0;

      .el-icon-close {
        font-size: 32px;
        color: #fff;
        margin-left: 15px;
        margin-top: 5px;

        &:hover {
          cursor: pointer;
        }

      }

    }
  }
</style>
